/******************************************************************************
 * Product: Adempiere ERP & CRM Smart Business Solution                       *
 * Copyright (C) 1999-2007 ComPiere, Inc. All Rights Reserved.                *
 * This program is free software, you can redistribute it and/or modify it    *
 * under the terms version 2 of the GNU General Public License as published   *
 * by the Free Software Foundation. This program is distributed in the hope   *
 * that it will be useful, but WITHOUT ANY WARRANTY, without even the implied *
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.           *
 * See the GNU General Public License for more details.                       *
 * You should have received a copy of the GNU General Public License along    *
 * with this program, if not, write to the Free Software Foundation, Inc.,    *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
 * For the text or an alternative of this public license, you may reach us    *
 * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA        *
 * or via info@compiere.org or http://www.compiere.org/license.html           *
 *****************************************************************************/
/** Generated Model - DO NOT CHANGE */
package org.compiere.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

/** Generated Model for hrm_sheduleemployee
 *  @author Adempiere (generated) 
 *  @version Release 3.7.0LTS - $Id$ */
public class X_hrm_sheduleemployee extends PO implements I_hrm_sheduleemployee, I_Persistent 
{

	/**
	 *
	 */
	private static final long serialVersionUID = 20120517L;
	
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (X_hrm_sheduleemployee.class);

    /** Standard Constructor */
    public X_hrm_sheduleemployee (Properties ctx, int hrm_sheduleemployee_ID, String trxName)
    {
      super (ctx, hrm_sheduleemployee_ID, trxName);
      /** if (hrm_sheduleemployee_ID == 0)
        {
			setC_BPartner_ID (0);
			setEndDate (new Timestamp( System.currentTimeMillis() ));
			sethrm_sheduleemployee_ID (0);
			sethrm_shedulerule_ID (0);
			setStartDate (new Timestamp( System.currentTimeMillis() ));
        } */
    }

    /** Load Constructor */
    public X_hrm_sheduleemployee (Properties ctx, ResultSet rs, String trxName)
    {
      super (ctx, rs, trxName);
    }

    /** AccessLevel
      * @return 3 - Client - Org 
      */
    protected int get_AccessLevel()
    {
      return accessLevel.intValue();
    }

    /** Load Meta Data */
    protected POInfo initPO (Properties ctx)
    {
      POInfo poi = POInfo.getPOInfo (ctx, Table_ID, get_TrxName());
      return poi;
    }

    public String toString()
    {
      StringBuffer sb = new StringBuffer ("X_hrm_sheduleemployee[")
        .append(get_ID()).append("]");
      return sb.toString();
    }

	public org.compiere.model.I_C_BPartner getC_BPartner() throws RuntimeException
    {
		return (org.compiere.model.I_C_BPartner)MTable.get(getCtx(), org.compiere.model.I_C_BPartner.Table_Name)
			.getPO(getC_BPartner_ID(), get_TrxName());	}

	/** Set Business Partner .
		@param C_BPartner_ID 
		Identifies a Business Partner
	  */
	public void setC_BPartner_ID (int C_BPartner_ID)
	{
		if (C_BPartner_ID < 1) 
			set_Value (COLUMNNAME_C_BPartner_ID, null);
		else 
			set_Value (COLUMNNAME_C_BPartner_ID, Integer.valueOf(C_BPartner_ID));
	}

	/** Get Business Partner .
		@return Identifies a Business Partner
	  */
	public int getC_BPartner_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_C_BPartner_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Description.
		@param Description 
		Optional short description of the record
	  */
	public void setDescription (String Description)
	{
		set_Value (COLUMNNAME_Description, Description);
	}

	/** Get Description.
		@return Optional short description of the record
	  */
	public String getDescription () 
	{
		return (String)get_Value(COLUMNNAME_Description);
	}

	/** Set End Date.
		@param EndDate 
		Last effective date (inclusive)
	  */
	public void setEndDate (Timestamp EndDate)
	{
		set_Value (COLUMNNAME_EndDate, EndDate);
	}

	/** Get End Date.
		@return Last effective date (inclusive)
	  */
	public Timestamp getEndDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_EndDate);
	}

	/** Set hrm_sheduleemployee.
		@param hrm_sheduleemployee_ID hrm_sheduleemployee	  */
	public void sethrm_sheduleemployee_ID (int hrm_sheduleemployee_ID)
	{
		if (hrm_sheduleemployee_ID < 1) 
			set_ValueNoCheck (COLUMNNAME_hrm_sheduleemployee_ID, null);
		else 
			set_ValueNoCheck (COLUMNNAME_hrm_sheduleemployee_ID, Integer.valueOf(hrm_sheduleemployee_ID));
	}

	/** Get hrm_sheduleemployee.
		@return hrm_sheduleemployee	  */
	public int gethrm_sheduleemployee_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_hrm_sheduleemployee_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	public I_hrm_shedulerule gethrm_shedulerule() throws RuntimeException
    {
		return (I_hrm_shedulerule)MTable.get(getCtx(), I_hrm_shedulerule.Table_Name)
			.getPO(gethrm_shedulerule_ID(), get_TrxName());	}

	/** Set hrm_shedulerule.
		@param hrm_shedulerule_ID hrm_shedulerule	  */
	public void sethrm_shedulerule_ID (int hrm_shedulerule_ID)
	{
		if (hrm_shedulerule_ID < 1) 
			set_Value (COLUMNNAME_hrm_shedulerule_ID, null);
		else 
			set_Value (COLUMNNAME_hrm_shedulerule_ID, Integer.valueOf(hrm_shedulerule_ID));
	}

	/** Get hrm_shedulerule.
		@return hrm_shedulerule	  */
	public int gethrm_shedulerule_ID () 
	{
		Integer ii = (Integer)get_Value(COLUMNNAME_hrm_shedulerule_ID);
		if (ii == null)
			 return 0;
		return ii.intValue();
	}

	/** Set Start Date.
		@param StartDate 
		First effective day (inclusive)
	  */
	public void setStartDate (Timestamp StartDate)
	{
		set_Value (COLUMNNAME_StartDate, StartDate);
	}

	/** Get Start Date.
		@return First effective day (inclusive)
	  */
	public Timestamp getStartDate () 
	{
		return (Timestamp)get_Value(COLUMNNAME_StartDate);
	}
	
	/** Load Model for hrm_sheduleemployee */
    public static X_hrm_sheduleemployee getSheduleemployee (int C_BPartner_ID)
    {
    	if(C_BPartner_ID == 0)
    		return null;
    	
    	X_hrm_sheduleemployee se = new X_hrm_sheduleemployee(Env.getCtx(), 0, null);
    	PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		// Employee data from the card
		String sql_ = "SELECT * FROM HRM_SHEDULEEMPLOYEE WHERE HRM_SHEDULEEMPLOYEE.AD_CLIENT_ID=? " +
				"AND HRM_SHEDULEEMPLOYEE.ISACTIVE='Y' " +
				"AND HRM_SHEDULEEMPLOYEE.C_BPARTNER_ID=?";
		try
		{
			pstmt = DB.prepareStatement(sql_,null);
			pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
			pstmt.setInt(2, C_BPartner_ID);
			rs = pstmt.executeQuery();
			if(rs.next())
				return new X_hrm_sheduleemployee(Env.getCtx(), rs, null);			
		}
		catch (SQLException e)
		{
			s_log.log(Level.SEVERE, "product", e);
		}
		finally
		{
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}
		return se;	
    }
	
}